package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test01 {
    public static void main(String[] args) {
        /** 创建银行账户对象 */
        Account account = new Account();
        /** 创建100线程池 */
        ExecutorService service = Executors.newFixedThreadPool(100);

        for(int i = 1; i <= 100; i++) {
            /** 调用构造方法 */
            service.execute(new AddMoneyThread(account, 1));
        }

        /** 关闭线程 */
        service.shutdown();
        /** 若关闭后所有任务都已完成，则返回true */
        while(!service.isTerminated()) {}

        System.out.println("账户余额: " + account.getBalance());
    }
}
